import cv2
import os

if __name__ == "__main__":
    video_path = (r"/home/kaijia/algo-env/Utils/sample/test_safety.mp4")
    cap = cv2.VideoCapture(video_path)
    left_top = (621, 263)
    right_top = (1554, 338)
    right_bottom = (1611, 394)
    left_bottom = (532, 280)
    color = (0, 255, 0)
    thickness = 2
    f_width = cap.get(cv2.CAP_PROP_FRAME_WIDTH)
    f_height = cap.get(cv2.CAP_PROP_FRAME_HEIGHT)
    f_shape = (int(f_width), int(f_height))
    four_cc = cv2.VideoWriter_fourcc(*'mp4v')
    video_writer = cv2.VideoWriter(
        r"/home/kaijia/algo-env/Utils/sample/done.mp4",
        four_cc, 5, f_shape)
    while True:
        _, frame = cap.read()
        if frame is None:
            break
        print("frame count ======>", cap.get(cv2.CAP_PROP_POS_FRAMES))
        frame = cv2.line(frame, left_top, right_top, color, thickness)
        frame = cv2.line(frame, right_top, right_bottom, color, thickness)
        frame = cv2.line(frame, right_bottom, left_bottom, color, thickness)
        frame = cv2.line(frame, left_bottom, left_top, color, thickness)
        video_writer.write(frame)
    cap.release()
    video_writer.release()
